package utils

import (
	"github.com/lionsoul2014/ip2region/binding/golang/ip2region"
	"higame/modules/log"
	"path"
)

func IP2Region(ip string) string {
	p := path.Join(RootPath(), "./assets/data/ip2region.db")
	region, err := ip2region.New(p)
	if err != nil {
		log.Error.Println(err)
		return ""
	}
	defer region.Close()
	if ip, err := region.MemorySearch(ip); err == nil {
		return ip.Province + ip.City + ip.ISP
	}
	return ""
}
